from core.support import set_cutscene
from core.item import Item
from core.action import Action
from items.octopus_ink import Octopus_Ink

class Knife(Item):
    def __init__(self):
        Item.__init__(self, "knife")    # do basic initialization for every item
        self.is_out = False
        
        # build list of actions
        self.add_action(UseKnife)
        #self.add_action(SheatheKnife)
    
    def get_description(self):
            return "Knife"

# define actions for this item

class UseKnife(Action):
    def __init__(self):
        Action.__init__(self, "use_knife")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use knife"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # enabled only if knife is in.
    def is_enabled(self):
        if self.item.is_out:
            return False
        else:
            return True
        
    # get knife out and add cutscene
    def do_action(self,game,room,request):
        if room.get_id() == 'octopus':
            if room.octopus_alive:
                set_cutscene('''You killed the octopus. You collect some ink.
                <audio autoplay="autoplay">
                <source src="images/knife-slice.mp3" type="audio/mp3" />
                Your browser does not support this audio
                </audio>''')
                room.octopus_alive = False
                player = game.get_player()
                player.add_item(Octopus_Ink())
            else:
                set_cutscene('''The octopus is already dead.
                <audio autoplay="autoplay">
                <source src="images/knife-slice.mp3" type="audio/mp3" />
                Your browser does not support this audio
                </audio>''')
        else:
            set_cutscene('''There is nothing to fight against.
            <audio autoplay="autoplay">
            <source src="images/knife-slice.mp3" type="audio/mp3" />
            Your browser does not support this audio
            </audio>''')
        return
    
class SheatheKnife(Action):
    def __init__(self):
        Action.__init__(self, "sheathe_knife")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Sheathe Knife"

    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"    
    
    # enabled only if lamp is out.
    def is_enabled(self):
        if self.item.is_out:
            return True
        else:
            return False
        
    # get knife in and add cutscene
    def do_action(self,game,room,request):
        self.item.is_out = False
        set_cutscene("You put your knife back in its sheath.")
        return
    